$(function () {
    //设备管理
    //基础配置
    //设备管理 打开窗口
    $('.configuration-trigger').on('click', function (event) {
        event.preventDefault();
        $('.configuration-pop').addClass('is-visible3');

        // 设备管理 首次渲染
        var configurationPage = 1;
        $("#configurationModal .devAddress").val('');
        $('.searchDevBox input').val('');
        $('#configurationModal .devTypeVal').val('全部')
        //        $('#configurationModal .devTypeVal option').eq(0).attr('selected');
        configurationPageList(configurationPage, '', '');
        // 设备管理 获取总页数 点击分页渲染列表
        configurationSumPage(configurationPage, '', '');
        $('.pageJump input').val('');
        $('#configurationModal .devAddress').val('');
        console.log($('#configurationModal .devTypeVal').find("option:contains('全部')"))

        // 渲染导出功能的列表
        $.ajax({
            url: '/deviceStatus/data/list/bydevicetype?deviceTypeId=1',
            success: function (res) {
                $('#configurationTableExport tbody').html('');
                var data = res.data;
                for (var i = 0; i < data.length; i++) {
                    var deviceName = data[i].device.deviceName ? data[i].device.deviceName : '';
                    var usestatus = data[i].device.usestatus ? data[i].device.usestatus : '';
                    var deviceTypeName = data[i].device.deviceType.deviceTypeName ? data[i].device.deviceType.deviceTypeName : '';
                    var devCode = data[i].device.devCode ? data[i].device.devCode : '';
                    var address = data[i].device.address ? data[i].device.address : '';
                    var fixedPlace = data[i].device.fixedPlace ? data[i].device.fixedPlace : '';
                    var latitude = data[i].device.latitude ? data[i].device.latitude : '';
                    var longitude = data[i].device.longitude ? data[i].device.longitude : '';
                    var installationDate = data[i].device.installationDate;
                    var deadline = data[i].device.deadline;

                    var linkMain1 = data[i].device.linkMain1 ? data[i].device.linkMain1 : '';
                    var linkPhone1 = data[i].device.linkPhone1 ? data[i].device.linkPhone1 : '';
                    var linkMain2 = data[i].device.linkMain2 ? data[i].device.linkMain2 : '';
                    var linkPhone2 = data[i].device.linkPhone2 ? data[i].device.linkPhone2 : '';
                    var linkMain3 = data[i].device.linkMain3 ? data[i].device.linkMain3 : '';
                    var linkPhone3 = data[i].device.linkPhone3 ? data[i].device.linkPhone3 : '';
                    var remark = data[i].device.remark ? data[i].device.remark : '';

                    installationDate = installationDate ? moment(installationDate).format("YYYY-MM-DD") : '';
                    deadline = deadline ? moment(installationDate).format("YYYY-MM-DD") : '';
                    $('#configurationTableExport tbody').append('<tr><td>' + deviceName + '</td><td>' + usestatus + '</td><td>' + deviceTypeName + '</td><td>' + devCode + '</td><td>' + address + '</td><td>' + fixedPlace + '</td><td>' + latitude + '</td><td>' + longitude + '</td><td>' + installationDate + '</td><td>' + deadline + '</td><td>' + linkMain1 + '</td><td>' + linkPhone1 + '</td><td>' + linkMain2 + '</td><td>' + linkPhone2 + '</td><td>' + linkMain3 + '</td><td>' + linkPhone3 + '</td><td>' + data[i].device.remark + '</td></tr>')
                }
                $('#configurationModal .exportBox .export').hide();
                $("#configurationTableExport caption").remove();
                $("#configurationTableExport").tableExport({
                    formats: ["xlsx"]
                });
            }
        });
    });
    // 设备管理     刷新
    $('#configurationRefresh').on('click', function () {

        //        $('#configurationModal .devTypeVal').find("option:contains('全部')").attr("selected",true);
        $('#configurationModal .devTypeVal').val('全部')
        // 设备管理 首次渲染
        var configurationPage = 1;
        $('.searchDevBox input').val('');
        $("#configurationModal .devAddress").val('');
        configurationPageList(configurationPage, '', '');
        // 设备管理 获取总页数 点击分页渲染列表
        configurationSumPage(configurationPage, '', '');
        $('.pageJump input').val('');
        $('#configurationModal .devAddress').val('');
        // 渲染导出功能的列表
        $.ajax({
            url: '/deviceStatus/data/list/bydevicetype?deviceTypeId=1',
            success: function (res) {
                $('#configurationTableExport tbody').html('');
                var data = res.data;
                for (var i = 0; i < data.length; i++) {
                    var deviceName = data[i].device.deviceName ? data[i].device.deviceName : '';
                    var usestatus = data[i].device.usestatus ? data[i].device.usestatus : '';
                    var deviceTypeName = data[i].device.deviceType.deviceTypeName ? data[i].device.deviceType.deviceTypeName : '';
                    var devCode = data[i].device.devCode ? data[i].device.devCode : '';
                    var address = data[i].device.address ? data[i].device.address : '';
                    var fixedPlace = data[i].device.fixedPlace ? data[i].device.fixedPlace : '';
                    var latitude = data[i].device.latitude ? data[i].device.latitude : '';
                    var longitude = data[i].device.longitude ? data[i].device.longitude : '';
                    var installationDate = data[i].device.installationDate;
                    var deadline = data[i].device.deadline;

                    var linkMain1 = data[i].device.linkMain1 ? data[i].device.linkMain1 : '';
                    var linkPhone1 = data[i].device.linkPhone1 ? data[i].device.linkPhone1 : '';
                    var linkMain2 = data[i].device.linkMain2 ? data[i].device.linkMain2 : '';
                    var linkPhone2 = data[i].device.linkPhone2 ? data[i].device.linkPhone2 : '';
                    var linkMain3 = data[i].device.linkMain3 ? data[i].device.linkMain3 : '';
                    var linkPhone3 = data[i].device.linkPhone3 ? data[i].device.linkPhone3 : '';
                    var remark = data[i].device.remark ? data[i].device.remark : '';

                    installationDate = installationDate ? moment(installationDate).format("YYYY-MM-DD") : '';
                    deadline = deadline ? moment(installationDate).format("YYYY-MM-DD") : '';
                    $('#configurationTableExport tbody').append('<tr><td>' + deviceName + '</td><td>' + usestatus + '</td><td>' + deviceTypeName + '</td><td>' + devCode + '</td><td>' + address + '</td><td>' + fixedPlace + '</td><td>' + latitude + '</td><td>' + longitude + '</td><td>' + installationDate + '</td><td>' + deadline + '</td><td>' + linkMain1 + '</td><td>' + linkPhone1 + '</td><td>' + linkMain2 + '</td><td>' + linkPhone2 + '</td><td>' + linkMain3 + '</td><td>' + linkPhone3 + '</td><td>' + data[i].device.remark + '</td></tr>')
                }
                $('#configurationModal .exportBox .export').hide();
                $("#configurationTableExport caption").remove();
                $("#configurationTableExport").tableExport({
                    formats: ["xlsx"]
                });
            }
        });
    });
    //设备管理  关闭窗口
    $('.configuration-pop').on('click', function (event) {
        if ($(event.target).is('.cd-popup-close') || $(event.target).is('.configuration-pop')) {
            event.preventDefault();
            $(this).removeClass('is-visible3');
        }
        if ($(event.target).is('.configuration-popup-close') || $(event.target).is('.configuration-pop')) {
            event.preventDefault();
            $(this).removeClass('is-visible3');
        }
        $('#configurationModal .devTypeVal').find("option:contains('全部')").attr("selected", true);

    });

    //设备管理 获取总页数 点击分页渲染列表
    function configurationSumPage(configurationPage, devCode, status) {
        console.log(configurationPage, devCode, status)
        var pageSum;
        var searchContent = $("#configurationModal .devAddress").val();
        if (searchContent) {
            searchContent = '&address=' + searchContent;
        } else {
            searchContent = '';
        }
        $.ajax({
            url: '/paging/data/list/bydevicetype/pageNumber?deviceTypeId=1' + status + devCode + searchContent,
            //      async: false,
            success: function (result) {
                pageSum = result.data;
                console.log(pageSum, configurationPage)
                configurationPageFunc(pageSum, configurationPage, devCode, status)
            }
        });
    }
    //设备管理  分页功能
    function configurationPageFunc(pageSum, configurationPage, devCode, status) {
        if (pageSum <= 1) {
            $('#configurationPageBox .pageJump').hide()
        } else {
            $('#configurationPageBox .pageJump').show()
        }
        Page({
            num: pageSum, //页码数
            startnum: configurationPage, //指定页码
            elem: $('#configurationPage'), //指定的元素
            callback: function (n) { //回调函数
                console.log(n);
                $('#configurationPageBox .pageJump').show();
                configurationPageList(n, devCode, status);
            }
        });
    };
    //设备管理  页面渲染列表
    function configurationPageList(n, devCode, status) {
        console.log(n, devCode, status)
        var searchContent = $("#configurationModal .devAddress").val();
        if (searchContent) {
            searchContent = '&address=' + searchContent;
        } else {
            searchContent = '';
        }
        $.ajax({
            url: '/paging/data/list/bydevicetype/approve?deviceTypeId=1' + status + searchContent + devCode + '&page=' + n,
            //      async: false,
            success: function (result) {
                console.log(result)
                $('#configurationModal .tbodyList').html('');
                configurationPage = n;
                var data = result.data;
                if (data.length != 0) {
                    for (var i = 0; i < data.length; i++) {
                        var beginTime = data[i].beginTime;
                        beginTime = moment(beginTime).format("YYYY-MM-DD HH:mm:ss");
                        var alarmId = data[i].alarmId;
                        var status = data[i].status;
                        if (status == 1) {
                            status = '火警';
                        } else if (status == 3) {
                            status = '故障';
                        } else if (status == 4) {
                            status = '低电';
                        } else if (status == 7) {
                            status = '正常';
                        }
                        //                  <span class="configBtnStyle modifyBtn editDevice-trigger">修改</span>
                        $('#configurationModal .tbodyList').append('<tr><td><input type="checkbox" class="check" devid="' + data[i].device.id + '"></td><td>' + ((+n - 1) * (+8) + (+i) + (+1)) + '</td><td>' + data[i].devCode + '</td><td>' + data[i].device.address + '</td><td>' + data[i].device.fireCount + '</td><td>' + status + '</td><td  devCode="' + data[i].devCode + '"longitude="' + data[i].device.longitude + '" latitude="' + data[i].device.latitude + '"><span class="configBtnStyle focusSelectBtn editDevice-trigger">查看详情</span><span class="configBtnStyle positionBtn closeModal configuration-popup-close" id="devicePositionBtn">定位</span></td></tr>')
                    }
                } else {
                    configurationPage = configurationPage - 1;
                    var devCode = $("#configurationModal .devCodeVal").val() ? '&devCode=' + $("#configurationModal .devCodeVal").val() : '';
                    var status = '';
                    status = $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') ? $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') : '';

                    if (status == "all") {
                        status = '';
                    } else {
                        status = '&status=' + status;
                    }
                    // 设备管理 首次渲染
                    configurationPageList(configurationPage, devCode, status);
                    // 设备管理 获取总页数 点击分页渲染列表
                    configurationSumPage(configurationPage, devCode, status);
                    $('.pageJump input').val('');
                }
            }
        });
    };
    //全选删除/全不选
    $('#configurationSelectAll').click(function () {
        var current = $(this).prop('checked');
        $('.check').prop({
            checked: current
        });
    });

    $('#configurationModal').on('click', '.check', function () {
        var flag = true;
        //  遍历下面所有的状态
        for (var i = 0; i < $('.check').length; i++) {
            //        如果其中一个不满足条件，把状态设置成false，立刻跳出循环
            if ($('.check').eq(i).prop('checked') == false) {
                flag = false;
                break;
            }
        }
        $('#configurationSelectAll').prop({
            checked: flag
        });
    });

    //设备管理 设备删除
    $("#configurationDelBtn").on('click', function () {
        $('#configurationModal .table .tbodyList input[type=checkbox]:checked').each(function () {
            var devid = $(this).attr('devid');
            console.log($(this), devid)
            $.ajax({
                url: '/device/del/' + devid,
                async: false,
                success: function (res) {
                    console.log(res)

                }
            });
        });
        var devCode = $("#configurationModal .devCodeVal").val() ? '&devCode=' + $("#configurationModal .devCodeVal").val() : '';
        var status = '';
        status = $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') ? $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') : '';

        if (status == "all") {
            status = '';
        } else {
            status = '&status=' + status;
        }
        console.log(configurationPage, devCode, status)
        // 设备管理 删除后重新渲染
        configurationPageList(configurationPage, devCode, status);
        $('.pageJump input').val('');
        devSumFunc();
        devListSum();
        tipModalFunc('删除成功!');
        $('#configurationSelectAll').prop('checked', false)
    });
    //设备管理 修改
    $('#configurationModal .manageModal .tableModal').on('click', '#deviceModifyBtn', function () {
        var $thisParent = $(this).parent();
        var devCode = $thisParent.attr('devcode');
        var alarmId = $thisParent.attr('alarmid');
        var disposeStatus = 1;
        configurationHandle(devCode, alarmId, disposeStatus);

        // 设备管理 获取总页数 点击分页渲染列表
        configurationSumPage(configurationPage, devCode, status);
        // 设备管理 首次渲染
        configurationPageList(configurationPage, devCode, status);
        $('.pageJump input').val('');

        //    弹出修改页面模态框

    });

    //设备管理 点击定位定位到地图
    $('#configurationModal .tableModal .tbodyList').on('click', '#devicePositionBtn', function () {
        var $thisParent = $(this).parent();
        var longitude = $thisParent.attr('longitude');
        var latitude = $thisParent.attr('latitude');
        var devCode = $thisParent.attr('devCode');
        console.log(longitude, latitude)
        BaiDuMap.panTo(latitude, longitude);
        setTimeout(function () {
            BaiDuMap.popMenu(devCode);
        }, 700);
        //  BaiDuMap.deletePoint
        //  BaiDuMap.addMarker(fireCount, status, devCode, deviceName, address,latitude,longitude, linkMain1, linkPhone1, linkMain2, linkPhone2, linkMain3, linkPhone3, linkMain4, linkPhone4)

        if ($(event.target).is('.editDevice-popup-close') || $(event.target).is('.editDevice-pop')) {
            event.preventDefault();
            $(this).removeClass('is-visible3');
        }

    });
    // 模糊查询
    searchFunc();

    function searchFunc() {
        var timeoutflag = null;

        //模糊查询
        $('body').on('click', function () {
            $("#configurationModal .searchList").hide();
        });
        $("#configurationModal .devAddress").on("input", function (e) {
            console.log('kk')
            $("#configurationModal .searchList").show();
            hide2border();
            if ($("#configurationModal .searchList li")) { //键盘抬起后就判断页面中是否存在这个元素,存在就删除
                $("#configurationModal .searchList li").remove();
            }
            var searchContent = $("#configurationModal .devAddress").val();
            searchContent = $.trim(searchContent);
            console.log(searchContent)
            //查询内容存在则搜索
            if (searchContent) {
                searchContent = '&address=' + searchContent;
                $.ajax({
                    url: "/device/data/list/bydeviceTypeandaddresslike?deviceTypeId=1" + searchContent,
                    type: "GET",
                    //                async: false,
                    success: function (result) {

                        if (result.status == "200") {
                            for (var i = 0; i < result.data.length; i++) {
                                var searchAddress = result.data[i].address;
                                var latitude = result.data[i].latitude;
                                var longitude = result.data[i].longitude;
                                var devCode = result.data[i].devCode;
                                console.log(searchAddress)
                                if (searchAddress) {
                                    $("#configurationModal .searchList").append('<li devicecode="' + devCode + '" longitude="' + longitude + '" latitude="' + latitude + '"><i class="fa fa-map-marker"></i>' + searchAddress + '</li>');
                                    hide2border();
                                }
                            }
                        } else {

                        }
                    }
                });

            }
            $("#configurationModal .searchList").show();
            hide2border();
        });
        //直接输入地址,点击列表查询
        $("#configurationModal .searchList").on("click", "li", function () {
            $("#configurationModal .searchList").show();
            var liVal = $(this).text();
            liVal = $.trim(liVal);
            var searchVal = $("#configurationModal .devAddress").val(liVal);

            $("#configurationModal .searchList").html(""); //hide
            return false;
        });
    }

    function hide2border() {
        if (!($("#configurationModal .searchList>li").length)) {
            $("#configurationModal .searchList").hide();
        } else {
            $("#configurationModal .searchList").show();
        }
    }
    //点击设备管理搜索按钮 deviceManageSearchBtn
    $("#deviceManageSearchBtn").on('click', function () {
        var devCode = $("#configurationModal .devCodeVal").val() ? '&devCode=' + $("#configurationModal .devCodeVal").val() : '';
        var devType = $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype');
        var status;
        if (devType == 'all') {
            status = '';
        } else {
            status = '&status=' + devType;
        }
        $('.pageJump input').val('');
        console.log(configurationPage, devCode, status);
        configurationSumPage(configurationPage, devCode, status);
        configurationPageList(1, devCode, status);
    });

    //设备编辑 打开窗口
    $('body').on('click', ".editDevice-trigger", function (event) {
        $('.devEditSureBtn').hide();
        $('.devEditBtn').show();
        event.preventDefault();
        $('.editDevice-pop').addClass('is-visible3');
        //获取当前设备信息
        var devCode = $(this).parent().attr('devCode');

        $('#editDeviceForm input.form-control').attr('disabled', 'disabled');
        $('#editDeviceForm select.form-control').attr('disabled', 'disabled');
        $('#editDeviceForm select.form-control').addClass('disabledStyle');
        $('#editDeviceForm input.form-control').addClass('disabledStyle');
        $.ajax({
            url: '/organization/list',
            async: false,
            success: function (res) {
                console.log(res)
                $('#editDeviceModal .orgidval').html('');
                for (var i = 0; i < res.data.length; i++) {
                    $('#editDeviceModal .orgidval').append('<option value="' + res.data[i].id + '">' + res.data[i].orgName + '</option>')
                }
            }
        });
        $.ajax({
            url: '/deviceStatus/get/code?deviceCode=' + devCode,
            async: false,
            success: function (res) {
                console.log(res)
                var deviceid = res.data[0][0].id;
                var deviceName = res.data[0][0].deviceName;
                var usestatus = res.data[0][0].usestatus;
                var deviceTypeName = res.data[0][0].deviceType.deviceTypeName;
                var deviceTypeId = res.data[0][0].deviceType.deviceTypeId;
                var devCode = res.data[0][0].devCode;
                var address = res.data[0][0].address;
                var fixedPlace = res.data[0][0].fixedPlace;
                var latitude = res.data[0][0].latitude;
                var longitude = res.data[0][0].longitude;
                var installationDate = res.data[0][0].installationDate;
                var deadline = res.data[0][0].deadline;
                var linkMain1 = res.data[0][0].linkMain1;
                var linkMain2 = res.data[0][0].linkMain2;
                var linkMain3 = res.data[0][0].linkMain3;
                var linkPhone1 = res.data[0][0].linkPhone1;
                var linkPhone2 = res.data[0][0].linkPhone2;
                var linkPhone3 = res.data[0][0].linkPhone3;
                var remark = res.data[0][0].remark;
                var fireCount = res.data[0][0].fireCount;
                installationDate = installationDate ? moment(installationDate).format("YYYY-MM-DD") : '';
                deadline = deadline ? moment(deadline).format("YYYY-MM-DD") : '';
                $('#editDeviceForm input[name="id"]').val(deviceid);
                $('#editDeviceForm input[name="deviceName"]').val(deviceName);
                $("#editDeviceForm select[name='usestatus']").val(usestatus);
                $('#editDeviceForm input[name="deviceTypeId"]').val(deviceTypeName);
                $('#editDeviceForm input[name="devCode"]').val(devCode);
                $('#editDeviceForm input[name="address"]').val(address);
                $('#editDeviceForm input[name="fixedPlace"]').val(fixedPlace);
                $('#editDeviceForm input[name="latitude"]').val(latitude);
                $('#editDeviceForm input[name="longitude"]').val(longitude);
                $('#editDeviceForm input[name="installationDate"]').val(installationDate);
                $('#editDeviceForm input[name="deadline"]').val(deadline);
                $('#editDeviceForm input[name="linkMain1"]').val(linkMain1);
                $('#editDeviceForm input[name="linkMain2"]').val(linkMain2);
                $('#editDeviceForm input[name="linkMain3"]').val(linkMain3);
                $('#editDeviceForm input[name="linkPhone1"]').val(linkPhone1);
                $('#editDeviceForm input[name="linkPhone2"]').val(linkPhone2);
                $('#editDeviceForm input[name="linkPhone3"]').val(linkPhone3);
                $('#editDeviceForm input[name="remark"]').val(remark);
                $('#editDeviceForm input[name="fireCount"]').val(fireCount);
                var orgname = res.data[0][1];
                $('#editDeviceForm .orgidval').find("option:contains('" + orgname + "')").attr("selected", true);
                $('#editDeviceForm .deviceTypeIdVal').find("option:contains('" + deviceTypeName + "')").attr("selected", true);
            }
        });
        //	$('#editDeviceForm input.form-control').attr('disabled');
    });
    //设备编辑  关闭窗口
    $('.editDevice-pop').on('click', function (event) {
        if ($(event.target).is('.cd-popup-close') || $(event.target).is('.editDevice-pop')) {
            event.preventDefault();
            $(this).removeClass('is-visible3');
            //Modal验证销毁重构
            $("#editDeviceForm").data('bootstrapValidator').destroy();
            $('#editDeviceForm').data('bootstrapValidator', null);
            editDeviceFormValidator();
            $('#editDeviceForm input').val('');
        }
    });
    editDeviceFormValidator();

    function editDeviceFormValidator() {
        $("#editDeviceForm").bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                devCode: {
                    message: '设备编号验证失败',
                    validators: {
                        notEmpty: {
                            message: '设备编号不能为空'
                        }
                    }
                },
                deviceTypeId: {
                    validators: {
                        notEmpty: {
                            message: '设备类型不能为空'
                        }
                    }
                },
                deviceName: {
                    validators: {
                        notEmpty: {
                            message: '设备名称不能为空'
                        }
                    }
                },
                address: {
                    validators: {
                        notEmpty: {
                            message: '安装地址不能为空'
                        }
                    }
                },
                fixedPlace: {
                    validators: {
                        notEmpty: {
                            message: '安装场所不能为空'
                        }
                    }
                },
                //            installationDate: {
                //                validators: {
                //                    notEmpty: {
                //                        message: '安装日期不能为空'
                //                    }
                //                }
                //            },
                latitude: {
                    validators: {
                        notEmpty: {
                            message: '经度不能为空'
                        }
                    }
                },
                longitude: {
                    validators: {
                        notEmpty: {
                            message: '纬度不能为空'
                        }
                    }
                }
            }
        }).on("success.form.bv", function (e) {
            e.preventDefault();
            var $form = $(e.target);
            var nextUrl;
            nextUrl = "/device/save?" + $form.serialize();
            console.log($form.serialize())
            $.ajax({
                url: nextUrl,
                type: 'POST',
                //            data: $form.serialize(),
                success: function (result) {
                    if (result.status == 200) {
                        $("#editDeviceForm").data('bootstrapValidator').destroy();
                        $('#editDeviceForm').data('bootstrapValidator', null);
                        editDeviceFormValidator();
                        $('#editDeviceForm input').val('');
                        $('.editDevice-pop').removeClass('is-visible3');
                        var devCode = $("#configurationModal .devCodeVal").val() ? '&devCode=' + $("#configurationModal .devCodeVal").val() : '';
                        var status = '';
                        status = $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') ? $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') : '';

                        if (status == "all") {
                            status = '';
                        } else {
                            status = '&status=' + status;
                        }
                        console.log(configurationPage, devCode, status)
                        // 设备管理 删除后重新渲染
                        configurationPageList(configurationPage, devCode, status);
                        tipModalFunc('修改成功!');
                    } else {
                        console.log(result.message);
                    }
                }

            });
        });
    }
    //点击修改按钮允许修改
    $("#deviceAllowEdit").on('click', function () {
        $('.devEditSureBtn').show();
        $('.devEditBtn').hide();
        $('#editDeviceForm input.form-control').removeAttr('disabled');
        $('#editDeviceForm select.form-control').removeAttr('disabled');
        $('#editDeviceForm select.form-control').removeClass('disabledStyle');
        $('#editDeviceForm input.form-control').removeClass('disabledStyle');
    });
    //设备添加 打开窗口
    $('body').on('click', '.addDevice-trigger', function (event) {
        event.preventDefault();
        $('#addDeviceForm select option').eq(0).prop('selected');
        $('.addDevice-pop').addClass('is-visible3');
        //    var installationDate = moment().format("YYYY-MM-DD");
        //    $('#addDeviceForm .installationDate').val(installationDate);
        $.ajax({
            url: '/organization/list',
            //		 async:false,
            success: function (res) {
                console.log(res)
                $('#addAccountModal .choiceOrgList').html('');
                $('#addDeviceModal .addAccountOrgList').html('');
                for (var i = 0; i < res.data.length; i++) {
                    $('#addDeviceModal .addAccountOrgList').append('<option value="' + res.data[i].id + '">' + res.data[i].orgName + '</option>')
                }
            }
        });
        $('#addDeviceModal .addAccountOrgList option').eq(0).attr("selected", true);
        $('#addDeviceModal .deviceTypeIdVal option').eq(0).attr("selected", true);
        $('#addDeviceModal .usestatusVal option').eq(0).attr("selected", true);

    });
    //设备添加  关闭窗口
    $('.addDevice-pop').on('click', function (event) {
        if ($(event.target).is('.cd-popup-close') || $(event.target).is('.addDevice-pop')) {
            event.preventDefault();
            $(this).removeClass('is-visible3');
            //Modal验证销毁重构
            $("#addDeviceForm").data('bootstrapValidator').destroy();
            $('#addDeviceForm').data('bootstrapValidator', null);
            deviceFormValidator();
            $('#addDeviceForm input').val('');
        }
    });
    deviceFormValidator();

    function deviceFormValidator() {
        $("#addDeviceForm").bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                devCode: {
                    message: '设备编号验证失败',
                    validators: {
                        notEmpty: {
                            message: '设备编号不能为空'
                        },
                        //                    regexp: {
                        //	                    regexp: /\s+$/
                        ////	                    message: '设备编号只能包含大写、小写、数字和下划线'
                        //	                }	                    

                    }
                },
                deviceTypeId: {
                    validators: {
                        notEmpty: {
                            message: '设备类型不能为空'
                        }
                    }
                },
                deviceName: {
                    validators: {
                        notEmpty: {
                            message: '设备名称不能为空'
                        }
                    }
                },
                address: {
                    validators: {
                        notEmpty: {
                            message: '安装地址不能为空'
                        }
                    }
                },
                fixedPlace: {
                    validators: {
                        notEmpty: {
                            message: '安装场所不能为空'
                        }
                    }
                },
                //            installationDate: {
                //                validators: {
                //                    notEmpty: {
                //                        message: '安装日期不能为空'
                //                    }
                //                }
                //            },
                latitude: {
                    validators: {
                        notEmpty: {
                            message: '经度不能为空'
                        }
                    }
                },
                longitude: {
                    validators: {
                        notEmpty: {
                            message: '纬度不能为空'
                        }
                    }
                }
            }
        }).on("success.form.bv", function (e) {
            e.preventDefault();
            var $form = $(e.target);
            var nextUrl;
            nextUrl = "/device/save",
                console.log($form.serialize())
            $.ajax({
                url: nextUrl,
                type: 'POST',
                data: $form.serialize(),
                success: function (result) {
                    console.log(result)
                    if (result.status == 200) {
                        $('.addDevice-pop').removeClass('is-visible3');
                        //Modal验证销毁重构
                        $("#addDeviceForm").data('bootstrapValidator').destroy();
                        $('#addDeviceForm').data('bootstrapValidator', null);
                        $('#addDeviceForm input').val('');
                        deviceFormValidator();
                        devSumFunc();
                        devListSum();
                        tipModalFunc('添加成功!');

                        var devCode = $("#configurationModal .devCodeVal").val() ? '&devCode=' + $("#configurationModal .devCodeVal").val() : '';
                        var status = '';
                        status = $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') ? $("#configurationModal .devTypeVal").find("option:selected").attr('alarmtype') : '';

                        if (status == "all") {
                            status = '';
                        } else {
                            status = '&status=' + status;
                        }
                        // 设备管理 首次渲染
                        //        	        configurationPageList(configurationPage,devCode,status);
                        console.log(configurationPage, devCode, status)
                        // 设备管理 获取总页数 点击分页渲染列表
                        configurationSumPage(configurationPage, devCode, status);

                    } else {
                        console.log(result.message);
                    }
                }

            });
        });
    }
    //-----------------------------------------------------------------------------
    // test();
    // function test(){
    //     $('.configuration-pop').addClass('is-visible3');

    //     // 设备管理 首次渲染
    //     var configurationPage = 1;
    //     $("#configurationModal .devAddress").val('');
    //     $('.searchDevBox input').val('');
    //     $('#configurationModal .devTypeVal').val('全部')
    //     //        $('#configurationModal .devTypeVal option').eq(0).attr('selected');
    //     configurationPageList(configurationPage, '', '');
    //     // 设备管理 获取总页数 点击分页渲染列表
    //     configurationSumPage(configurationPage, '', '');
    //     $('.pageJump input').val('');
    //     $('#configurationModal .devAddress').val('');
    //     console.log($('#configurationModal .devTypeVal').find("option:contains('全部')"))

    //     // 渲染导出功能的列表
    //     $.ajax({
    //         url: '/deviceStatus/data/list/bydevicetype?deviceTypeId=1',
    //         success: function (res) {
    //             $('#configurationTableExport tbody').html('');
    //             var data = res.data;
    //             for (var i = 0; i < data.length; i++) {
    //                 var deviceName = data[i].device.deviceName ? data[i].device.deviceName : '';
    //                 var usestatus = data[i].device.usestatus ? data[i].device.usestatus : '';
    //                 var deviceTypeName = data[i].device.deviceType.deviceTypeName ? data[i].device.deviceType.deviceTypeName : '';
    //                 var devCode = data[i].device.devCode ? data[i].device.devCode : '';
    //                 var address = data[i].device.address ? data[i].device.address : '';
    //                 var fixedPlace = data[i].device.fixedPlace ? data[i].device.fixedPlace : '';
    //                 var latitude = data[i].device.latitude ? data[i].device.latitude : '';
    //                 var longitude = data[i].device.longitude ? data[i].device.longitude : '';
    //                 var installationDate = data[i].device.installationDate;
    //                 var deadline = data[i].device.deadline;

    //                 var linkMain1 = data[i].device.linkMain1 ? data[i].device.linkMain1 : '';
    //                 var linkPhone1 = data[i].device.linkPhone1 ? data[i].device.linkPhone1 : '';
    //                 var linkMain2 = data[i].device.linkMain2 ? data[i].device.linkMain2 : '';
    //                 var linkPhone2 = data[i].device.linkPhone2 ? data[i].device.linkPhone2 : '';
    //                 var linkMain3 = data[i].device.linkMain3 ? data[i].device.linkMain3 : '';
    //                 var linkPhone3 = data[i].device.linkPhone3 ? data[i].device.linkPhone3 : '';
    //                 var remark = data[i].device.remark ? data[i].device.remark : '';

    //                 installationDate = installationDate ? moment(installationDate).format("YYYY-MM-DD") : '';
    //                 deadline = deadline ? moment(installationDate).format("YYYY-MM-DD") : '';
    //                 $('#configurationTableExport tbody').append('<tr><td>' + deviceName + '</td><td>' + usestatus + '</td><td>' + deviceTypeName + '</td><td>' + devCode + '</td><td>' + address + '</td><td>' + fixedPlace + '</td><td>' + latitude + '</td><td>' + longitude + '</td><td>' + installationDate + '</td><td>' + deadline + '</td><td>' + linkMain1 + '</td><td>' + linkPhone1 + '</td><td>' + linkMain2 + '</td><td>' + linkPhone2 + '</td><td>' + linkMain3 + '</td><td>' + linkPhone3 + '</td><td>' + data[i].device.remark + '</td></tr>')
    //             }
    //             $('#configurationModal .exportBox .export').hide();
    //             $("#configurationTableExport caption").remove();
    //             $("#configurationTableExport").tableExport({
    //                 formats: ["xlsx"]
    //             });
    //         }
    //     });
    // }










});